package com.cskaoyan.javase.homework.day05.oop1;

/**
 * 对象与类基础语法练习题
 * 设计类Item
 *
 * @since 11:34
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class ClazzBasicDemo {
    public static void main(String[] args) {
        Item it1 = new Item();
        it1.name = "Samsung Galaxy S21";
        it1.category = "手机";
        it1.price = 8000;
        Item it2 = new Item();
        it2.name = "海尔冰箱";
        it2.category = "家具";
        it2.price = 3000;
        Item it3 = new Item();
        it3.name = "海飞丝洗发水";
        it3.category = "日用品";
        it3.price = 30;

        System.out.println(it1.sell(7000));
        System.out.println(it2.sell(5000));
        System.out.println(it3.sell(50));
    }
}

// 注意不要定义内部类
class Item {
    String name;
    double price;
    String category;

    public double sell(double money) {
        if (money > price) {
            System.out.println("种类为" + category + "的物品:" + name + "被出售了！");
            return money - price;
        }
        System.out.println("金钱不足，购买失败！");
        return -1;
    }
}